import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import {SharedModule} from '../shared.module';
import {MODAL_WIDTH} from '../../const'
import {Salary} from '../../types/resp/Salary';

@Component({
  selector: 'salary-view',
  imports: [
    SharedModule
  ],
  templateUrl: './salary-view.component.html',
  standalone: true
})
export class SalaryViewComponent implements OnInit {
  salaryForm!: FormGroup;
  isVisible: boolean = false
  title: string = '员工薪资详情'
  modalWidth: string = MODAL_WIDTH

  constructor(
    private fb: FormBuilder
  ) {}

  ngOnInit(): void {
    this.salaryForm = this.fb.group({
      employeeName: [''],
      basicSalary: [0],
      performanceSalary: [0],
      bonus: [0],
      allowance: [0],
      overtimePay: [0],
      socialSecurityDeduction: [0],
      housingFundDeduction: [0],
      personalIncomeTaxDeduction: [0],
      otherDeductions: [0],
      grossSalary: [0],
      netSalary: [0],
      payDate: [''],
      paymentMethod: [undefined],
      bankAccountNumber: [''],
      createTime: [''],
      modifyTime: [''],
    })
  }

  onBack() {
    this.isVisible = false
  }

  display(salary: Salary) {
    this.isVisible = true
    this.salaryForm.patchValue(salary);
    this.salaryForm.disable();
  }
}
